<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link href="../StaticFiles/element-plus-2.9.1/index.css" rel="stylesheet">
  <link href="../StaticFiles/nprogress/nprogress.min.css" rel="stylesheet">
  <link href="../styles/vue-page-common.css" rel="stylesheet">
  <script src="../Scripts/pollyfills/Array.prototype.flat.js"></script><!-- es6 数组flat兼容 -->
  <script src="../Scripts/pollyfills/ResizeObserver.js"></script><!-- es6 ResizeObserver兼容  -->
  <script src="../StaticFiles/vue3/vue.global.prod.js"></script>
  <script src="../StaticFiles/element-plus-2.9.1/index.full.min.js"></script>
  <script src="../StaticFiles/element-plus-2.9.1/icons-vue.js"></script><!-- 引入icon -->
  <script src="../StaticFiles/element-plus-2.9.1/zh-cn.min.js"></script><!-- 国际化 -->
  <script src="../Scripts/axios.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/crypto-js.js"></script>
  <script src="../Scripts/secret.js"></script>
  <title>热表零组件收发台账</title>
  <style>
    .el-table--large .cell {
      padding: 0 10px !important;
    }
  </style>
</head>

<body>
  <div id="app" v-cloak>
    <vue3-report-header title="热表零组件收发台账"></vue3-report-header>
    <div style="padding: 10px;" @keyup.enter="getData">
      <!-- 查询条件区 -->
      <el-form :inline="true" :model="dataObj.queryInfo" ref="queryInfoRef" :label-position="'left'">
        <el-form-item label="委托单位:">
          <el-select style="width: 160px;" v-model="dataObj.queryInfo.fromfactoryid" placeholder="请选择委托单位" clearable
            filterable>
            <el-option v-for="f in dataObj.factoryList" :key="f.factoryid" :label="f.factoryname" :value="f.factoryid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="承制分厂:">
          <el-input v-model="dataObj.queryInfo.tofactoryname" :disabled="true"></el-input>
        </el-form-item>

        <el-form-item label="型别:">
          <el-select style="width: 160px;" v-model="dataObj.queryInfo.familylistnames" placeholder="请选择型别" clearable
            filterable>
            <el-option v-for="i in dataObj.productFamilyList" :key="i.productfamilyid" :label="i.productfamilyname"
              :value="i.productfamilyid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item prop='productname' label="零件图号:">
          <el-autocomplete v-model.trim="dataObj.queryInfo.productname" placeholder="请输入零件图号" :trigger-on-focus="false"
            :fetch-suggestions="getProductnameAsync" :value-key="'productname'" :debounce="500" style="width:250px;">
          </el-autocomplete>
        </el-form-item>

        <el-form-item label="委托单位批次号:">
          <el-autocomplete v-model.trim="dataObj.queryInfo.containername" placeholder="请输入" :trigger-on-focus="false"
            style="width:400px;" :fetch-suggestions="searchContainerAsync" :value-key="'containername'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item label="承制单位批次号:">
          <el-autocomplete v-model.trim="dataObj.queryInfo.rbcontainername" placeholder="请输入" :trigger-on-focus="false"
            style="width:400px;" :fetch-suggestions="searchContainerAsync" :value-key="'containername'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item label="工序号:">
          <el-input v-model.trim="dataObj.queryInfo.specno" placeholder="请输入" clearable style="width: 100px;">
          </el-input>
        </el-form-item>

        <el-form-item label="接收人:">
          <el-select v-model="dataObj.queryInfo.receiver" placeholder="请选择" clearable filterable style="width: 120px;">
            <el-option v-for="w in dataObj.factoryUserList" :key="w.employeeid" :label="w.fullname"
              :value="w.employeeid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="接收时间:">
          <el-date-picker v-model="dataObj.queryInfo.recivedate" type="daterange" range-separator="至"
            start-placeholder="开始日期" end-placeholder="结束日期" value-format="YYYY-MM-DD" :shortcuts="dataObj.shortcuts">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="完成日期:">
          <el-date-picker v-model="dataObj.queryInfo.completedate" type="daterange" range-separator="至"
            start-placeholder="开始日期" end-placeholder="结束日期" value-format="YYYY-MM-DD" :shortcuts="dataObj.shortcuts">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="完成人:">
          <el-select v-model="dataObj.queryInfo.completeemp" placeholder="请选择" clearable filterable
            style="width: 120px;">
            <el-option v-for="w in dataObj.factoryUserList" :key="w.employeeid" :label="w.fullname"
              :value="w.employeeid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="数据来源:">
          <el-select v-model="dataObj.queryInfo.sourcetype" placeholder="请选择" clearable filterable
            style="width: 140px;">
            <el-option :key="'正常批次'" :label="'正常批次'" :value="'正常批次'"></el-option>
            <el-option :key="'无订单批次'" :label="'无订单批次'" :value="'无订单批次'"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="无订单批次委托单位:" v-show="dataObj.queryInfo.sourcetype === '无订单批次'">
          <el-input v-model.trim="dataObj.queryInfo.wtdw" placeholder="请输入" clearable></el-input>
        </el-form-item>

        <el-form-item label="无订单批次委托批次:" v-show="dataObj.queryInfo.sourcetype === '无订单批次'">
          <el-input v-model.trim="dataObj.queryInfo.wtpc" placeholder="请输入" clearable></el-input>
        </el-form-item>

        <el-form-item label="单元格合并显示:">
          <el-switch v-model="dataObj.mergeCell" inactive-text="" active-text=""></el-switch>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" :icon="'Search'" size="default" @click="getData">查询</el-button>
          <el-button type="primary" :icon="'Download'" size="default" @click="getExportExcel">导出</el-button>
        </el-form-item>
      </el-form>

      <!-- 表格 -->
      <el-table :data="dataObj.dataList" stripe border show-overflow-tooltip v-loading.fullscreen.lock="dataObj.loading"
        :element-loading-text="dataObj.loadingText" element-loading-background="rgba(0,0,0,0.8)"
        :span-method="handleSpanMethod">
        <el-table-column type="index" width="60"></el-table-column>
        <el-table-column prop="sourcetype" label="数据来源" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column prop="mfgordername" label="订单号" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column prop="fromfactory" label="委托单位" width="120" show-overflow-tooltip></el-table-column>
        <el-table-column prop="productname" label="零件号" width="120" show-overflow-tooltip></el-table-column>
        <el-table-column prop="productdescription" label="名称" width="120" show-overflow-tooltip></el-table-column>
        <el-table-column prop="containername" label="委托单位批次号" width="120" show-overflow-tooltip></el-table-column>
        <!-- <el-table-column prop="childcontainername" label="子序号" width="120" show-overflow-tooltip></el-table-column> -->
        <el-table-column prop="rbcontainername" label="承制单位批次号" width="200" show-overflow-tooltip></el-table-column>
        <el-table-column prop="workflowinfo" label="工艺信息" width="140" show-overflow-tooltip></el-table-column>
        <el-table-column prop="familylistnames" label="型别" width="120" show-overflow-tooltip></el-table-column>
        <el-table-column prop="specno" label="工序号" width="80"></el-table-column>
        <el-table-column prop="workflowstepname" label="工序内容" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column prop="receiveqty" label="收入数量" width="80"></el-table-column>
        <el-table-column prop="receivedate" label="收入日期" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column prop="receiver" label="收入者" width="80"></el-table-column>
        <el-table-column prop="completeqty" label="完成数量" width="80"></el-table-column>
        <el-table-column prop="completedate" label="完成日期" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column prop="completeemp" label="完成人" width="80"></el-table-column>
        <el-table-column prop="checkemployeename" label="检验员" width="80"></el-table-column>
      </el-table>

      <!-- 分页 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="dataObj.currentPage" :page-sizes="[dataObj.pageSize,20,50]" :page-size="dataObj.pageSize"
        layout="prev,pager,next,jumper,sizes,total" :total="dataObj.total">
      </el-pagination>

      <!-- 回到顶部 -->
      <el-backtop></el-backtop>
    </div>
  </div>
  <script type="module">
    import { getProductFamily, exportExcel, getFactory, getParams, fetchSuggestion } from '../Scripts/hooks/useCommonMethod.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/vue3DateShortCut.js'
    import { splitDate } from '../Scripts/hooks/format.js'
    import { getSpanArr } from '../Scripts/hooks/spanMethod.js'
    import Vue3ReportHeader from '../Scripts/components/Vue3ReportHeader.js';
    const { createApp, reactive, ref, onMounted, watch } = Vue
    const { ElMessage } = ElementPlus
    const App = {
      setup() {
        const dataObj = reactive({
          loading: false,
          loadingText: '数据加载中...',
          currentPage: 1,// 当前页
          pageSize: 12, // 每页显示条数
          total: 0,
          factoryList: [],
          productFamilyList: [],// 机型
          factoryUserList: [],
          queryInfo: {
            tofactoryid: '',//承制分厂id
            tofactoryname: '',// 承制分厂名称
            fromfactoryid: '',// 主制分厂id
            familylistnames: '',// 机型
            productname: '', // 件号
            containername: '', //流水卡号
            rbcontainername: '',// 热表批次号
            receiver: '',// 接收人
            recivedate: [], // 接收时间
            completeemp: '', // 完成人
            completedate: [], // 完成时间
            specno: '', // 工序号
            sourcetype: '', //数据来源
            wtdw: '',//无订单批次委托单位
            wtpc: ''//无订单批次委托批次
          },
          dataList: [],
          shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth],
          mergeCell: true,
          mergeColumns: [],
          mergeData: {}
        })

        // 查询图号
        async function getProductnameAsync(value, callback) {
          fetchSuggestion({ actionName: 'getProductnameAsync', name: 'productname', value, callback, triggerLength: 2 });
        }

        // 查询批次号
        async function searchContainerAsync(value, callback) {
          fetchSuggestion({ actionName: 'getContainernameAsync', name: 'containername', value, callback, triggerLength: 2 })
        }

        // 查询承制分厂信息
        async function getToFactoryName() {
          const { data: { data } } = await axios({
            url: '../handler/report/CommonActionHandle.ashx?actions=getFactoryInfo',
            method: 'post',
            data: { type: 'getFactoryInfo', factoryid: Decrypt(getParams('factoryid')), isMapping: '是' }
          })
          const { factoryid, factoryname } = data[0];
          dataObj.queryInfo.tofactoryname = factoryname;
          dataObj.queryInfo.tofactoryid = factoryid;
        }

        // 查询分厂所有人员
        async function getFactoryUsers() {
          const { data: { data } } = await axios({
            url: '../handler/report/CommonActionHandle.ashx?actions=getFactoryUsers',
            method: 'post',
            data: { type: 'getFactoryUsers', factorycode: '602' }
          })
          dataObj.factoryUserList = data;
        };

        // 查询数据
        async function getData() {
          dataObj.loading = true;
          dataObj.loadingText = '数据加载中...';
          const { data: { data, meta, total } } = await axios({
            url: '../handler/report/RbContainerShipTZReport.ashx?actions=getData',
            method: 'post',
            data: {
              ...dataObj.queryInfo,
              currentPage: dataObj.currentPage,
              pageSize: dataObj.pageSize,
              type: 'getData'
            }
          })
          dataObj.loading = false;
          if (meta.status === 500) {
            return ElMessage.error(meta.msg);
          }
          dataObj.dataList = data;
          dataObj.total = total;

          // 合并单元格
          if (data.length > 0) {
            dataObj.mergeColumns = Object.keys(data[0]);
            for (const i of dataObj.mergeColumns) {
              dataObj.mergeData[i] = getSpanArr(data, i);
            }
          }
        };

        // 导出excel
        function getExportExcel() {
          const config = {
            url: '../handler/report/RbContainerShipTZReport.ashx?actions=exportExcel',
            data: { ...dataObj.queryInfo }
          }
          exportExcel(config, dataObj, ElMessage)
        };

        function handleCurrentChange(newPage) {
          dataObj.currentPage = newPage;
          getData();
        };

        function handleSizeChange(newSize) {
          dataObj.pageSize = newSize;
          getData();
        };

        // 合并单元格方法
        function handleSpanMethod({ row, column, rowIndex, columnIndex }) {
          if (!dataObj.mergeCell) { return; }
          if (dataObj.mergeColumns.includes(column.property)) {
            const _row = dataObj.mergeData[column.property][rowIndex];
            const _col = _row > 0 ? 1 : 0;
            return { rowspan: _row, colspan: _col };
          }
        };

        onMounted(() => {
          getToFactoryName() //查询承制分厂信息
          getProductFamily(dataObj)
          getFactory(dataObj)
          getFactoryUsers()
          const monday = dayjs().startOf('week').add(1, 'day').format('YYYY-MM-DD');
          const sunday = dayjs().endOf('week').add(1, 'day').format('YYYY-MM-DD');
          dataObj.queryInfo.recivedate = [monday, sunday] // 收入日期默认本周
        })

        watch(() => dataObj.queryInfo, () => {
          dataObj.currentPage = 1;
        }, { deep: true })

        return {
          dataObj,
          getData,
          getExportExcel,
          handleCurrentChange,
          handleSizeChange,
          getProductnameAsync,
          searchContainerAsync,
          splitDate,
          handleSpanMethod
        }
      }
    };

    const app = createApp(App);
    app.use(ElementPlus, {
      locale: ElementPlusLocaleZhCn,
      size: 'large'
    });
    // 注册所有icon
    for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
      app.component(key, component)
    }
    app.component('vue3-report-header', Vue3ReportHeader);
    app.mount('#app');
  </script>
</body>

</html>